﻿namespace TC
{
    public class Switch_tree : TranslateTree
    {
        public override editor.cfg.behaviourtree.TreeNode OnTranslate(Node node)
        {
            SwitchInt t = node as SwitchInt;
            editor.cfg.behaviourtree.Switch re = new editor.cfg.behaviourtree.Switch();
            re.id = t.id;

            Port p = t.graph.GetConnect(t.selection);
            if(p == null)
            {
                throw new System.Exception("Switch selection is null");
            }

            re.selector = new editor.cfg.blueprint.OutputPin() { nodeId = p.parent.id, pinName = p.name };

            foreach (var i in t.cases)
            {
                p = t.graph.GetConnect(i.Value);
                if(p != null)
                {
                    re.flows.Add(i.Key, BTGraphExport.translate[p.parent.GetType()].OnTranslate(p.parent));
                }
            }

            return re;
        }
    }
}
